#pragma once
#include <game/Config.h>

#include <string>

#include <memory>
#include <map>
#include <boost/function.hpp>

ARELLO_GAME_NAMESPACE_DECL_START

class ScreenBackend;

typedef boost::function<std::auto_ptr<ScreenBackend> ()> BackendCreator;

/** This object collects mapping between backend creators and their names. Anyone may request to
*	create concrete backend here */
class ScreenBackendFactory
{
public:
	ScreenBackendFactory();
	ScreenBackendFactory(const ScreenBackendFactory& rhs);
	ScreenBackendFactory& operator=(const ScreenBackendFactory& rhs);
	~ScreenBackendFactory();

	/** Tries to create screen backend with given name. If backend creator with that name wasn't
	*	registered, returns empty auto_ptr */
	std::auto_ptr<ScreenBackend> CreateBackend(const std::string& name);

	/** Maps given name to given backend creator. Throws Gluck if backend creator with given 
	* name is already registered */
	void RegisterBackendCreator(const std::string& name, const BackendCreator& creator);
private:
	typedef std::map<std::string, BackendCreator > CreatorMap;
	CreatorMap creators;
};

ARELLO_GAME_NAMESPACE_DECL_END